# Makefile 
#
# Created on: 2012-02-06
#     Author: Huabo Zheng
# @Copyright: 2012, www.netgear.com Inc. All rights reserved.
#make X86=1 
#export LD_LIBRARY_PATH=../../Framework/lib:../../gmock/lib/.libs:../../gmock/gtest/lib/.libs:/usr/local/lib:.

BINARY = lcdappd_unit_test

ifdef X86
CC = gcc
CXX = g++
else
CC = mips64-octeon-linux-gnu-gcc -mabi=n32
CXX = mips64-octeon-linux-gnu-g++ -mabi=n32
endif

DEBUG_FLAGS ?= -g
OPTIMIZE_FLAG ?= -O0
GCOV_FLAGS =  -fprofile-arcs -ftest-coverage
DYNLIBFLAGS = -shared -fPCI
CXXFLAGS ?= $(DEBUG_FLAGS) $(OPTIMIZE_FLAG) -DHAVE_INTTYPES_H

GMOCK_DIR = ../../gmock
GMOCK_INC = $(GMOCK_DIR)/include
GTEST_INC = $(GMOCK_DIR)/gtest/include
INC_DIRS = -I$(GMOCK_INC) -I$(GTEST_INC) -I../include -I../../Framework/include -I../../Framework/include/lcd
LD_DIRS = -L$(GMOCK_DIR)/lib/.libs  -L$(GMOCK_DIR)/gtest/lib/.libs  -L/usr/local/lib -L../lib -L$(GMOCK_DIR)/lib -L$(GMOCK_DIR)/gtest/lib -L../../Framework/lib
ifndef X86
INC_DIRS += -I/usr/local/include
LD_DIRS += -L/usr/local/lib
endif

LIBS ?= -lpthread -lgtest -lgmock -llcdappframework

SOURCE_FILES = $(wildcard *.cpp)
OBJECT_FILES = $(SOURCE_FILES:.cpp=.o)

all: $(BINARY)

%.d: %.cpp
	@$(CXX) -MM $(CXXFLAGS) $(INC_DIRS) $< \
	| sed 's#\($*\)\.o[ :]*#$(OUT_DIR)/\1.o $@ : #g' > $@; \
	[ -s $@ ] || rm -f $@

%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(INC_DIRS) -c -o $@ $<

ifneq ($(MAKECMDGOALS),clean)
include $(DEP_FILES)
endif

$(BINARY): $(OBJECT_FILES)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(INC_DIRS) $(LD_DIRS) -o $@ $^ $(LIBS)
	
.PHONY: clean
clean:
	-rm -rf $(BINARY) $(OBJECT_FILES) $(DEP_FILES) $(GCOV_FILES) 
